﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DSTheLoaiHoa : System.Web.UI.Page
{
    chitiettheloaihoa cttl = new chitiettheloaihoa();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        string ma = Request.QueryString["id"];
        if (ma == null)
            Response.Redirect("TrangChu.aspx");
            //return;
       DTLDSHoa.DataSource = cttl.danhmuchoa(ma);
       DTLDSHoa.DataBind();
       if (IsPostBack)
           return;
       
    }
    DataTable tbl = new DataTable();
 
    protected void DTLDSHoa_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "chon")
        {
            string Mahoa = e.CommandArgument.ToString();
            Session["Mahoa"] = Mahoa;

            string Maloai = DTLDSHoa.DataKeys[0].ToString();
            Session["Maloai"] = Maloai;
            Response.Redirect("CThoa.aspx");
        }
        if (e.CommandName == "select")
        {
            if (Session["hoa"] == null)
            {
                tbl.Columns.Add("mahoa", typeof(string));
                tbl.Columns.Add("tenhoa", typeof(string));
                tbl.Columns.Add("giahoa", typeof(float));
                tbl.Columns.Add("soluong", typeof(int));
                tbl.Columns.Add("thanhtien", typeof(float), "soluong*giahoa");
                Session["hoa"] = tbl;
            }
            tbl = (DataTable)Session["hoa"];
           Label tenhoa = (Label)e.Item.FindControl("lblTenhoa");
            Label gia = (Label)e.Item.FindControl("lblGiahoa");
            tbl.Rows.Add(e.CommandArgument.ToString(),tenhoa.Text, gia.Text,1);
            int count = tbl.Rows.Count;
            Session["hoa"] = tbl;
           // Response.Redirect("DSTheLoaiHoa.aspx");
          Response.Redirect(Request.Path);
        }
    }
}
